From 48a535073130ce4063ca4a15f510a5122f7f9fb7 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 6 Feb 2009 10:40:00 +0000 Subject: [PATCH] x86: Move interrupt vector management from io_apic.c to irq.c Signed-off-by: Espen Skoglund --- xen/arch/x86/io_apic.c | 54 ----------------------------------------- xen/arch/x86/irq.c | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index 3f2c3426ff..c767d175bb 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -49,7 +49,6 @@ atomic_t irq_mis_count; static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; static DEFINE_SPINLOCK(ioapic_lock); -static DEFINE_SPINLOCK(vector_lock); int skip_ioapic_setup; @@ -89,9 +88,6 @@ static struct irq_pin_list { }; static int irq_2_pin_free_entry = NR_IRQS; -int vector_irq[NR_VECTORS] __read_mostly = { - [0 ... NR_VECTORS - 1] = FREE_TO_ASSIGN}; - /* * The common case is 1:1 IRQ<->pin mappings. Sometimes there are * shared ISA-space IRQs, so we have to support them. We are super @@ -669,56 +665,6 @@ static inline int IO_APIC_irq_trigger(int irq) /* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */ u8 irq_vector[NR_IRQS] __read_mostly; -int free_irq_vector(int vector) -{ - int irq; - - BUG_ON((vector > LAST_DYNAMIC_VECTOR) || (vector < FIRST_DYNAMIC_VECTOR)); - - spin_lock(&vector_lock); - if ((irq = vector_irq[vector]) == AUTO_ASSIGN) - vector_irq[vector] = FREE_TO_ASSIGN; - spin_unlock(&vector_lock); - - return (irq == AUTO_ASSIGN) ? 0 : -EINVAL; -} - -int assign_irq_vector(int irq) -{ - static unsigned current_vector = FIRST_DYNAMIC_VECTOR; - unsigned vector; - - BUG_ON(irq >= NR_IRQS); - - spin_lock(&vector_lock); - - if ((irq != AUTO_ASSIGN) && (IO_APIC_VECTOR(irq) > 0)) { - spin_unlock(&vector_lock); - return IO_APIC_VECTOR(irq); - } - - vector = current_vector; - while (vector_irq[vector] != FREE_TO_ASSIGN) { - vector += 8; - if (vector > LAST_DYNAMIC_VECTOR) - vector = FIRST_DYNAMIC_VECTOR + ((vector + 1) & 7); - - if (vector == current_vector) { - spin_unlock(&vector_lock); - return -ENOSPC; - } - } - - current_vector = vector; - vector_irq[vector] = irq; - if (irq != AUTO_ASSIGN) - IO_APIC_VECTOR(irq) = vector; - - spin_unlock(&vector_lock); - - return vector; -} - static struct hw_interrupt_type ioapic_level_type; static struct hw_interrupt_type ioapic_edge_type; diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index f0e8d599db..2587b0736c 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -27,6 +27,11 @@ boolean_param("noirqbalance", opt_noirqbalance); irq_desc_t irq_desc[NR_VECTORS]; +static DEFINE_SPINLOCK(vector_lock); +int vector_irq[NR_VECTORS] __read_mostly = { + [0 ... NR_VECTORS - 1] = FREE_TO_ASSIGN +}; + static void __do_IRQ_guest(int vector); void no_action(int cpl, void *dev_id, struct cpu_user_regs *regs) { } @@ -54,6 +59,56 @@ struct hw_interrupt_type no_irq_type = { atomic_t irq_err_count; +int free_irq_vector(int vector) +{ + int irq; + + BUG_ON((vector > LAST_DYNAMIC_VECTOR) || (vector < FIRST_DYNAMIC_VECTOR)); + + spin_lock(&vector_lock); + if ((irq = vector_irq[vector]) == AUTO_ASSIGN) + vector_irq[vector] = FREE_TO_ASSIGN; + spin_unlock(&vector_lock); + + return (irq == AUTO_ASSIGN) ? 0 : -EINVAL; +} + +int assign_irq_vector(int irq) +{ + static unsigned current_vector = FIRST_DYNAMIC_VECTOR; + unsigned vector; + + BUG_ON(irq >= NR_IRQS); + + spin_lock(&vector_lock); + + if ((irq != AUTO_ASSIGN) && (IO_APIC_VECTOR(irq) > 0)) { + spin_unlock(&vector_lock); + return IO_APIC_VECTOR(irq); + } + + vector = current_vector; + while (vector_irq[vector] != FREE_TO_ASSIGN) { + vector += 8; + if (vector > LAST_DYNAMIC_VECTOR) + vector = FIRST_DYNAMIC_VECTOR + ((vector + 1) & 7); + + if (vector == current_vector) { + spin_unlock(&vector_lock); + return -ENOSPC; + } + } + + current_vector = vector; + vector_irq[vector] = irq; + if (irq != AUTO_ASSIGN) + IO_APIC_VECTOR(irq) = vector; + + spin_unlock(&vector_lock); + + return vector; +} + asmlinkage void do_IRQ(struct cpu_user_regs *regs) { unsigned int vector = regs->entry_vector; -- 2.30.2